﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZK.YHP_TransManage.Test
{
    public partial class Testlock : Form
    {
        public Testlock()
        {
            InitializeComponent();
            Common.DelegateHelper.InfoMessageEvent += SetNr;
        }


        int num = 0;
        private void button1_Click(object sender, EventArgs e)
        {

            aa(1);
            aa(2);
            aa(3);
            aa(4);
            aa(5);
            aa(6);
            aa(7);
        }

        public void SetNr(string i)
        {
            this.Invoke(new Action(() => { textBox1.AppendText("次" + System.Threading.Thread.CurrentThread.ManagedThreadId + "\n"); }));
        }
        public static object obj = new object();
        public void aa(int ii)
        {
            lock (obj)
            {
                textBox1.AppendText(num + "` \n");
                num += 1;
                Common.DelegateHelper.InfoMessageEvent.Invoke("-" + num);
                System.Threading.Thread.Sleep(500);
                //textBox1.AppendText("主" + System.Threading.Thread.CurrentThread.ManagedThreadId + "\n");
                textBox1.AppendText(num + "\n");
                //SetNr(num); 
            }
        }
    }
}
